﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductionManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductionManagement.ProdBatchMaterialRecordVMs
{
    public partial class ProdBatchMaterialRecordListVM : BasePagedListVM<ProdBatchMaterialRecord_View, ProdBatchMaterialRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProdBatchMaterialRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<ProdBatchMaterialRecord_View>>{
                
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_MaterialCode).SetTitle(@Localizer["Page.物料编码"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_Barcode).SetTitle(@Localizer["Page.物料条码"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_Wo).SetTitle(@Localizer["Page.归属工单"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_Qty).SetTitle(@Localizer["Page.当前批次数量"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_UsedQty).SetTitle(@Localizer["Page.已使用数量"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_LineId).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_LineCode).SetTitle(@Localizer["Page.产线编号"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_OpId).SetTitle(@Localizer["Page.工位号"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_OpCode).SetTitle(@Localizer["Page.用料工序编号"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_FeedingTime).SetTitle(@Localizer["Page.上料时间"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_ScanOpId).SetTitle(@Localizer["Page.扫码工位"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_ScanOpCode).SetTitle(@Localizer["Page.扫码工位编号"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_FeedingBy).SetTitle(@Localizer["Page.投料人"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProdBatchMaterialRecord_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProdBatchMaterialRecord_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionBatchMaterialRecord>()
                
                .CheckContain(Searcher.MaterialCode, x=>x.MaterialCode)
                .CheckContain(Searcher.Barcode, x=>x.Barcode)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.Qty, x=>x.Qty)
                .CheckEqual(Searcher.UsedQty, x=>x.UsedQty)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckBetween(Searcher.FeedingTime?.GetStartTime(), Searcher.FeedingTime?.GetEndTime(), x => x.FeedingTime, includeMax: false)
                .CheckEqual(Searcher.ScanOpId, x=>x.ScanOpId)
                .CheckContain(Searcher.ScanOpCode, x=>x.ScanOpCode)
                .CheckContain(Searcher.FeedingBy, x=>x.FeedingBy)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProdBatchMaterialRecord_View
                {
				    ID = x.ID,
                    
                    ProdBatchMaterialRecord_MaterialCode = x.MaterialCode,
                    ProdBatchMaterialRecord_Barcode = x.Barcode,
                    ProdBatchMaterialRecord_Wo = x.Wo,
                    ProdBatchMaterialRecord_Qty = x.Qty,
                    ProdBatchMaterialRecord_UsedQty = x.UsedQty,
                    ProdBatchMaterialRecord_LineId = x.LineId,
                    ProdBatchMaterialRecord_LineCode = x.LineCode,
                    ProdBatchMaterialRecord_OpId = x.OpId,
                    ProdBatchMaterialRecord_OpCode = x.OpCode,
                    ProdBatchMaterialRecord_FeedingTime = x.FeedingTime,
                    ProdBatchMaterialRecord_ScanOpId = x.ScanOpId,
                    ProdBatchMaterialRecord_ScanOpCode = x.ScanOpCode,
                    ProdBatchMaterialRecord_FeedingBy = x.FeedingBy,
                    ProdBatchMaterialRecord_CreateTime = x.CreateTime,
                    ProdBatchMaterialRecord_UpdateTime = x.UpdateTime,
                    ProdBatchMaterialRecord_CreateBy = x.CreateBy,
                    ProdBatchMaterialRecord_UpdateBy = x.UpdateBy,
                    ProdBatchMaterialRecord_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProdBatchMaterialRecord_View: ProductionBatchMaterialRecord
    {
        
        public string ProdBatchMaterialRecord_MaterialCode { get; set; }
        public string ProdBatchMaterialRecord_Barcode { get; set; }
        public string ProdBatchMaterialRecord_Wo { get; set; }
        public decimal? ProdBatchMaterialRecord_Qty { get; set; }
        public decimal? ProdBatchMaterialRecord_UsedQty { get; set; }
        public long? ProdBatchMaterialRecord_LineId { get; set; }
        public string ProdBatchMaterialRecord_LineCode { get; set; }
        public long? ProdBatchMaterialRecord_OpId { get; set; }
        public string ProdBatchMaterialRecord_OpCode { get; set; }
        public DateTime? ProdBatchMaterialRecord_FeedingTime { get; set; }
        public long? ProdBatchMaterialRecord_ScanOpId { get; set; }
        public string ProdBatchMaterialRecord_ScanOpCode { get; set; }
        public string ProdBatchMaterialRecord_FeedingBy { get; set; }
        public DateTime? ProdBatchMaterialRecord_CreateTime { get; set; }
        public DateTime? ProdBatchMaterialRecord_UpdateTime { get; set; }
        public string ProdBatchMaterialRecord_CreateBy { get; set; }
        public string ProdBatchMaterialRecord_UpdateBy { get; set; }
        public bool ProdBatchMaterialRecord_IsValid { get; set; }

    }

}